import java.util.Scanner;

public class demo05 {
    //出迷宫
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] arr1=new String[10];
        char[][] arr=new char[10][10];
        for (int i = 0; i < 10; i++) {
            arr1[i]=sc.next();
            arr[i]=arr1[i].toCharArray();
        }
        int count=0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                int[][] num=new int[10][10];
                if(func(arr,i,j,num)){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
    public static boolean func(char[][] arr,int i,int j,int[][] num){
        while (true){
            num[i][j]=1;
            char ch=arr[i][j];
            if(ch=='D'){
                i+=1;
            }else if (ch=='U'){
                i-=1;
            } else if (ch=='L') {
                j-=1;
            }else{
                j+=1;
            }
            if(i<0||i>=10||j<0||j>=10){
                return true;
            }
            if(num[i][j]==1){
                break;
            }
        }
        return false;
    }
}
